<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<form>
    用户名<input name="userName"><br>
    密码<input type="password" name="pass"><br>
    <a href="login.html">已有账号直接登陆</a>
    <input type="button" value="注册" onclick="registUser()">
</form>

<script>

function registUser(){
    //先去获取所有的用户,将新注册的用户插入进去
    var form1 = document.forms[0];
    var User ={
        name:form1.userName.value.trim(),
        pass:form1.pass.value.trim()
    };

    var users = localStorage.getItem("users");
    users = !users ? [] : JSON.parse(users);

//    不能重复注册
    if(users.length>0){
//        item=>item.name==User.name&&item.pass==User.pass
//        function (item){
//            return item.name==User.name&&item.pass==User.pass
//        }
        let tt = users.some(item=>item.name==User.name&&item.pass==User.pass);
        if(tt)
        throw "已经注册过了，不能在注册";
    }
    users.push(User);
    localStorage.setItem("users",JSON.stringify(users));
    location.href="login.html"
}
</script>

</body>
</html>